
<?php
	require_once('../process/connect_db.php');
	$user = $_POST['user'];
	$pass = $_POST['pass'];
	
			
	if(!is_null($user) && !is_null($pass) && $user != "" && $pass != ""){
		$db = new bd("admins");

		$query="Select user, pass, nom_torneig From admins";
		$reg=$db->consulta($query);	
	
		
		if(sizeof($reg) > 0 && $reg[0]['user'] == $user && $reg[0]['pass'] == $pass){
			session_start();
			
			// TODO Major complexitat a l'autentificacio
			$rand = rand(0,100000);
			$_SESSION['cookies'] = $rand;
			$nom_torneig = $reg[0]['nom_torneig'];
			$query="Update admins Set session = \"" .$rand. "\" Where nom_torneig = \"" . $nom_torneig . "\"";
			$db->executar($query);
			header("location: ../forms/f_admin.php");
			
		} else {
			header("location: ../forms/f_autent.php");
		}
		
	} else {
		header("location: ../forms/f_autent.php");
	}

?>

